import { ipcRenderer } from 'electron'
import { ApiType } from '../types'

export const api: ApiType = {
  // 服务器主机连接配置 CRUD
  saveHostConnConfs: (hostConnConfs) => {
    return ipcRenderer.invoke(IpcChannelNameConst.saveHostConnConfs, hostConnConfs)
  },
  findHostConnConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.findHostConnConfs, options)
  },
  removeHostConnConfsByIds: (ids) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeHostConnConfsByIds, ids)
  },
  // 服务器主机连接测试
  testConn: (hostConnConf) => {
    return ipcRenderer.invoke(IpcChannelNameConst.testConn, hostConnConf)
  },
  // 本机终端会话
  shellSessionOpen: (channel) => {
    return ipcRenderer.invoke(IpcChannelNameConst.shellSessionOpen, channel)
  },
  shellSessionExec: (channel, cmd) => {
    return ipcRenderer.invoke(IpcChannelNameConst.shellSessionExec, channel, cmd)
  },
  shellSessionClose: (channel) => {
    return ipcRenderer.invoke(IpcChannelNameConst.shellSessionClose, channel)
  },
  // 服务器主机 SSH 会话
  SSHSessionOpen: (channel, config) => {
    return ipcRenderer.invoke(IpcChannelNameConst.SSHSessionOpen, channel, config)
  },
  SSHSessionExec: (channel, cmd) => {
    return ipcRenderer.invoke(IpcChannelNameConst.SSHSessionExec, channel, cmd)
  },
  SSHSessionClose: (channel) => {
    return ipcRenderer.invoke(IpcChannelNameConst.SSHSessionClose, channel)
  },
  // 命令配置 CRUD
  saveCmdConfs: (cmdConfs) => {
    return ipcRenderer.invoke(IpcChannelNameConst.saveCmdConfs, cmdConfs)
  },
  findCmdConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.findCmdConfs, options)
  },
  removeCmdConfsByIds: (ids) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeCmdConfsByIds, ids)
  },
  // 脚本配置 CRUD
  saveScriptConfs: (scriptConfs) => {
    return ipcRenderer.invoke(IpcChannelNameConst.saveScriptConfs, scriptConfs)
  },
  findScriptConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.findScriptConfs, options)
  },
  removeScriptConfsByIds: (ids) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeScriptConfsByIds, ids)
  },
  // 脚本节点配置 CRUD
  saveScriptNodeConfs: (scriptNodeConfs) => {
    return ipcRenderer.invoke(IpcChannelNameConst.saveScriptNodeConfs, scriptNodeConfs)
  },
  findScriptNodeConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.findScriptNodeConfs, options)
  },
  removeScriptNodeConfsByIds: (ids) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeScriptNodeConfsByIds, ids)
  },
  removeScriptNodeConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeScriptNodeConfs, options)
  },
  // 脚本节点边配置 CRUD
  saveScriptEdgeConfs: (scriptEdgeConfs) => {
    return ipcRenderer.invoke(IpcChannelNameConst.saveScriptEdgeConfs, scriptEdgeConfs)
  },
  findScriptEdgeConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.findScriptEdgeConfs, options)
  },
  removeScriptEdgeConfsByIds: (ids) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeScriptEdgeConfsByIds, ids)
  },
  removeScriptEdgeConfs: (options) => {
    return ipcRenderer.invoke(IpcChannelNameConst.removeScriptEdgeConfs, options)
  }
}
